package com.ysxsoft.wdg.ui.activity.my;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.response.DlLevelBean;
import com.ysxsoft.wdg.bean.response.MyBagResponse;
import com.ysxsoft.wdg.bean.response.MyShouYiResponse;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.net.UrlHost;
import com.ysxsoft.wdg.util.JsonUtils;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.sp.SharePrefUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;

public class AccountActivity extends BaseActivity {

    public static void start(Context context) {
        Intent intent = new Intent(context, AccountActivity.class);
        context.startActivity(intent);
    }


    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_finish)
    ImageView titleFinish;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_tv_r)
    TextView titleTvR;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_wei_money)
    TextView tvWeiMoney;
    @BindView(R.id.tv_ti_money)
    TextView tvTiMoney;
    @BindView(R.id.tv_tx)
    TextView tvTx;
    @BindView(R.id.tv_byyg)
    TextView tvByyg;
    @BindView(R.id.tv_jrsy)
    TextView tvJrsy;
    @BindView(R.id.tv_syjs)
    TextView tvSyjs;
    @BindView(R.id.tv_yjfl)
    TextView tvYjfl;
    @BindView(R.id.tv_tdjl)
    TextView tvTdjl;
    @BindView(R.id.tv_dljl)
    TextView tvDljl;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_account;
    }

    @Override
    protected void initData() {
        initStatusBar(topView, false);
        titleContent.setText("我的账户");
        titleTvR.setText("提现记录");
    }

    @Override
    protected void onResume() {
        super.onResume();
        getMyAccount();
        getMyShouYi();
    }

    @Override
    protected void setListener() {

    }


    @OnClick({R.id.title_finish, R.id.title_tv_r, R.id.ll_byyg,
            R.id.ll_jrsy, R.id.ll_syjs, R.id.ll_yjfl,
            R.id.ll_tdjl, R.id.ll_dljl, R.id.tv_tx})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.title_tv_r:
                TxHisActivity.start(mContext);
                break;
            case R.id.ll_byyg:
                SyActivity.start(mContext, 1,m1);
                break;
            case R.id.ll_jrsy:
                SyActivity.start(mContext, 2,m2);
                break;
            case R.id.ll_syjs:
                SyActivity.start(mContext, 3,m3);
                break;
            case R.id.ll_yjfl:
                SyActivity.start(mContext, 4,m4);
                break;
            case R.id.ll_tdjl:
                SyActivity.start(mContext, 5,m5);
                break;
            case R.id.ll_dljl:
                SyActivity.start(mContext, 6,m6);
                break;
            case R.id.tv_tx:
                TxActivity.start(mContext);
                break;
        }
    }


    /**
     * 获取我的账户
     */
    private void getMyAccount() {
        OkHttpUtils.post()
                .url(UrlHost.ACCOUNT_INFO)
                .addParams("uid", SharePrefUtils.getUserId())
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                if (!call.isCanceled()) {
                }
            }

            @Override
            public void onResponse(String response, int id) {
                if (response != null) {
                    MyBagResponse myBagResponse = JsonUtils.parseByGson(response, MyBagResponse.class);
                    if (myBagResponse == null) {
                        return;
                    }
                    if (CallbackCode.SUCCESS.equals(myBagResponse.getCode())) {
                        MyBagResponse.DataBean da = myBagResponse.getData();
                        if (da != null) {
                            tvMoney.setText(da.getRu());
                            tvTiMoney.setText(da.getMoney());
                            tvWeiMoney.setText(da.getYu());
//                            tvWeiMoney.setText(da.getMoney());
                        }
                    } else {
                        ToastUtils.showToast(myBagResponse.getMs());
                    }
                } else {
                }
            }
        });
    }

    /**
     * 获取我的收益
     */
    private void getMyShouYi() {
        OkHttpUtils.post()
                .url(UrlHost.ACCOUNT_SHOU)
                .addParams("uid", SharePrefUtils.getUserId())
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                if (!call.isCanceled()) {
                }
            }

            @Override
            public void onResponse(String response, int id) {
                if (response != null) {
                    MyShouYiResponse myShouYiResponse = JsonUtils.parseByGson(response, MyShouYiResponse.class);
                    if (myShouYiResponse == null) {
                        return;
                    }
                    if (CallbackCode.SUCCESS.equals(myShouYiResponse.getCode())) {
                        MyShouYiResponse.DataBean da = myShouYiResponse.getData();
                        if (da != null) {
                            m1=da.getY_now_month();
                            m2=da.getNow_today();
                            m3=da.getLast_month();
                            m4=da.getFen();
                            m5=da.getTuan();
                            m6=da.getDai();
                            tvByyg.setText(da.getY_now_month());//本月收益
                            tvJrsy.setText(da.getNow_today());//今日收益
                            tvSyjs.setText(da.getLast_month());//上月结算
                            tvYjfl.setText(da.getFen());//一级返利
                            tvTdjl.setText(da.getTuan());//团队奖励
                            tvDljl.setText(da.getDai());//代理奖励
                        }
                    } else {
                        ToastUtils.showToast(myShouYiResponse.getMs());
                    }
                } else {
                }
            }
        });
    }

    private String m1="0",m2="0",m3="0",m4="0",m5="0",m6="0";

}
